# encoding=utf-8
import numpy as np

# 定义短语翻译概率
P = {
    ('我', 'I'): 0.5,
    ('爱', 'love'): 0.7,
    ('你', 'you'): 0.6,
    ('的', 'your'): 0.8,
    ('猫', 'cat'): 0.4,
    ('狗', 'dog'): 0.3,
}

# 定义源语言和目标语言的句子
source = '我 爱 你 的 猫'
target = 'I love your cat'

# 将句子分解为短语
source_phrases = [tuple(source.split()[i:i+2]) for i in range(0, len(source.split()), 2)]
target_phrases = [tuple(target.split()[i:i+2]) for i in range(0, len(target.split()), 2)]

# 定义翻译概率矩阵
P_matrix = np.zeros((len(source_phrases), len(target_phrases)))
for i, source_phrase in enumerate(source_phrases):
    for j, target_phrase in enumerate(target_phrases):
        if source_phrase[1] == target_phrase[1]:
            P_matrix[i, j] = P[source_phrase, target_phrase[0]]

# 计算最大似然翻译
best_translation = []
for i in range(len(source_phrases)):
    max_prob = 0
    max_index = 0
    for j in range(len(target_phrases)):
        if P_matrix[i, j] > max_prob:
            max_prob = P_matrix[i, j]
            max_index = j
    best_translation.append(target_phrases[max_index][0])

# 输出翻译结果
print(' '.join(best_translation))
